package com.mk.graphql.resolver;

import com.mk.graphql.entity.Author;
import com.mk.graphql.repository.Repository;
import graphql.kickstart.tools.GraphQLMutationResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Random;

@Component
public class AuthorMutation implements GraphQLMutationResolver {

    @Autowired
    private Repository repository;

    public Author saveAuthor(Author author) {
        author.setId(author.getId());
        author.setName("addName");
        author.setSex("男");
        author.setCreatedTime(new Date());
        repository.put(author.getId(), author);
        return author;
    }

    public Boolean delAuthor(Long id) {
        repository.del(id);
        return true;
    }
}
